package test
{
	import mx.core.UIComponent;
	import flash.display.Sprite;
	import mx.controls.Button;
	
	public class MyComponent extends UIComponent
	{
		private var content:Sprite;
		
		private var buttons:Array = [];
		
		private var _buttonCountChanged:Boolean = true;
		
		private var _buttonCount:int = 2;
		public function set buttonCount(value:int):void
		{
			if(_buttonCount != value && value>=0)	
			{
				_buttonCount = value;
				_buttonCountChanged = true;
			}
		}
		
		public function MyComponent()
		{
			super();
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			if(!content)
			{
				content = new Sprite();
				//content.width = 200;
				//content.height = 300;
				this.addChild(content);
			}
			var b:Button = new Button();
			b.label = "testButton";
			b.width = 100;
			b.height = 100;
			this.addChild(b);
		}
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			/* this.graphics.lineStyle(1, 0x21ff00, 2.5);
			this.graphics.beginFill(0xff00ff,1.0);
			this.graphics.drawEllipse(20,30,200,100);
			this.graphics.endFill(); */
			
			this.content.graphics.lineStyle(1, 0xff0000, 0.5);
			this.content.graphics.beginFill(0xe30120,1.0);
			this.content.graphics.drawEllipse(20,30,100,300);
			this.content.graphics.endFill();
			refreshSeries();
		}
		override protected function measure():void
		{
			super.measure();
		}
		override protected function commitProperties():void
		{
			super.commitProperties();
			
			if(_buttonCountChanged)
			{
				
				for(var i:int =0;i<_buttonCount;i++)
				{
					
				}
				_buttonCountChanged = false;
			}
		}
		
		private function refreshSeries():void
		{
			var seriesCount:int = this.content.numChildren;
			for(var i:int = seriesCount-1; i >=0 ; i--)
			{
				this.content.removeChildAt(i);
			}
			
			//b.move(200,300);
		}
	}
}